package com.sdtv.mediunfusion;

import android.util.Log;
import android.widget.TextView;

import com.blankj.utilcode.util.LogUtils;
import com.sdtv.basemodule.annotations.CreatePresenter;
import com.sdtv.basemodule.annotations.PresenterVariable;
import com.sdtv.basemodule.base.BaseActivity;
import com.sdtv.basemodule.cache.DaoUtils;
import com.sdtv.basemodule.rx.BaseSignalObserver;
import com.sdtv.mediunfusion.bean.TestBean;
import com.sdtv.mediunfusion.mvp.contract.MainContract;
import com.sdtv.mediunfusion.mvp.contract.MainPresenter;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

@CreatePresenter(presenter = MainPresenter.class)
public class MainActivity extends BaseActivity implements MainContract.MainView {

    private static final String TAG = "MainActivity";

    @PresenterVariable
    MainPresenter presenter;
    @BindView(R.id.testButton)
    TextView testButton;
    private int page = 1;

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }


    @Override
    public void initView() {
    }

    @Override
    public void initData() {
        showLoading();
        presenter.getTestData();
    }


    @OnClick(R.id.testButton)
    public void onViewClicked() {
        Log.e(TAG, "onViewClicked: hahaha");
        DaoUtils.queryDataFromDatabase("page" + page)
                .subscribe(new BaseSignalObserver<TestBean.DatasBean>(TestBean.DatasBean.class) {
                    @Override
                    public void onNext(List<TestBean.DatasBean> dataList) {
                        LogUtils.e("数据程度 ： " + dataList.size());
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        // 获取缓存数据失败了 或者缓存数据为空--都会执行该方法
                    }
                });
        page++;

    }

    @Override
    public void changeText(String text) {
        testButton.setText(text);
    }

}
